console.log('detail');
const $side = $('<div class="side"></div>');
const $combine_btn = $('<button class="combine">组合信息</button>');
const $copy_btn = $('<button class="copy">复制url</button>');
const $postFree = $('<p class="postFree"><span>包邮</span></p>');
const $serivce = $('<p class="serivce"><span>晚发必赔</span><span>7天无理由退货</span><span>退货包运费</span><span>极速退款</span></p>');
const $tiktok = $('<p class="tiktok"><span>抖音</span></p>');
const $credit = $('<p class="credit"><span>先采后付</span></p>');
const $data = $('<p class="data"><span></span><span></span><span></span></p>');
const $desc = $('<input type="text">');
$side.append($combine_btn).append($copy_btn).append($postFree).append($tiktok).append($serivce).append($credit).append(
	$data).append($desc);
$('body').append($side);
$copy_btn.click(() => {
	let copy_text = `${location.href}&备注=${$desc.val()}`;
	navigator.clipboard.writeText(copy_text);
});
$combine_btn.click(() => {
	$side.find('*').removeClass('strikethrough');
	$.get(location.href, (res) => {
		html = res;
		let guaranteeList = html.match(/guaranteeList.*?]/s)[0];
		// alert(a);
		// console.log($serivce.find('span').length);
		// console.log(html.indexOf('"postFree":true'));
		if (html.indexOf('"postFree":true') == -1) {
			$postFree.find('span').addClass('strikethrough');
		}
		// console.log(guaranteeList);
		$serivce.find('span').each((i, it) => {
			let name = $(it).text();
			// console.log(name);
			// console.log(name == '包邮');
			// console.log((guaranteeList.indexOf(name)== -1));
			if (guaranteeList.indexOf(name) == -1) {
				$(it).addClass('strikethrough');
			}
		});
	});
	const $tiktokImg = $('img[src*="6000000006562-2-tps-45-45.png"]');
	if ($tiktokImg.length == 0) {
		$tiktok.find('span').addClass('strikethrough');
	}
	const $creditImg = $('img[src*="6000000002822-2-tps-186-46.png"]');
	if ($tiktokImg.length == 0) {
		$credit.find('span').addClass('strikethrough');
	}
	const $evalBox = $data.find('span:eq(0)');
	const $evalNum = $('.haopinlv span:eq(1)');
	let evalNum = $evalNum.text().match(/\d*/)[0];
	// console.log($('.zzb_item_label:contains("好评率")+div'));
	// console.log(evalNum);
	// console.log($evalNum.text());
	// console.log($('iframe').find('.zzb_item_label'));
	$evalBox.text(`好评率：${evalNum}%`);
	if (isNaN(evalNum) || evalNum < 90) {
		$data.find('span:eq(0)').addClass('strikethrough');
	}
	const $postBox = $data.find('span:eq(1)');
	const $postLv = $('span:contains("48小时发货率")+span');
	let postNum = $postLv.text().match(/\d*/)[0];
	$postBox.text(`48H发货率：${postNum}%`);
	if (isNaN(postNum) || postNum < 95) {
		$data.find('span:eq(1)').addClass('strikethrough');
	}
	const $modelBox = $data.find('span:eq(2)');
	const $model = $('span.jingymoshi');
	let model_text = $model.text();
	$modelBox.text(model_text);
	if (model_text.indexOf('生产') == -1) {
		$data.find('span:eq(2)').addClass('strikethrough');
	}
	
	let leimi_val = $('.leimi .val').text();
	$desc.val(leimi_val);
});